﻿/**
* 贝塞尔线条。
*/
Ext.define('Happy.designer.BezierLine', {
    extend: 'Happy.designer.Line',

    /**
     * @cfg {Object} 控制点偏移配置。
     */
    controlOffsetConfig: {
        left: { x: -60, y: 0 },
        bottom: { x: 0, y: 60 },
        right: { x: 60, y: 0 },
        top: { x: 0, y: -60 }
    },

    /**
     * @inheritdoc
     */
    createLinePath: function (config) {
        var me = this;

        var control1 = me.getControlPoint(config.startCycle);
        var control2 = me.getControlPoint(config.endCycle || config.startCycle);

        return [
            'M', config.start.x, config.start.y,
            'C', control1.x, control1.y, control2.x, control2.y, config.end.x, config.end.y
        ].join(' ');
    },

    /**
     * @inheritdoc
     */
    createArrawPath: function (config) {
        var me = this;

        var util = Happy.designer.PointUtil;

        var control2 = me.getControlPoint(config.endCycle || config.startCycle);

        var angle = util.angle(control2, config.end);

        var points = util.createArrawPoints(config.end, angle, 8);

        return util.createLinePath(points);
    },

    /**
     * 创建控制点。
     * 
     * @private
     * @param {Object} cycle
     * @return {Object}
     */
    getControlPoint: function (cycle) {
        var me = this;

        return {
            x: cycle.attr.x + me.controlOffsetConfig[cycle.position].x,
            y: cycle.attr.y + me.controlOffsetConfig[cycle.position].y
        };
    }
});